const http = require('http')
const ops = {
    host: '116.62.34.123',
    port: 8080,
    path: '/tracer/statistic/excel',
    method: 'POST',
    headers: {
        'Content-Type': 'application/json; charset=UTF-8',
    },
}

function getExcelData(data) {
    let json = '';
    return new Promise((resolve, reject) => {
        let req = http.request(ops, res => {
            res.setEncoding('utf8');
            res.on('data', response => {
                json += response
            })
            res.on('end', () => {
                try {
                    resolve(JSON.parse(json))
                } catch (error) {
                    reject(error)
                }
            })
        });
        req.on('error', (err) => {
            reject(err)
        })
        req.write(data)
        req.end()
    })
}

module.exports = getExcelData
